package com.zero.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.zero.entity.Family;
import com.zero.entity.FamilyMember;
import com.zero.service.FamilyMemberService;
import com.zero.service.FamilyService;
import com.zero.util.Page;
import com.zero.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/family")
public class FamilyController {

    @Autowired
    private FamilyService familyService;

    @Autowired
    private FamilyMemberService familyMemberService;

    /**
     * 获得登陆者个人信息的接口
     * @param request
     * @return
     */
    @GetMapping("/userInfo")
    public Result getUserInfo(HttpServletRequest request){
        return familyMemberService.getUserInfo(request);
    }

    /**
     * 获取家庭信息
     * @param request
     * @return
     */
    @GetMapping("/familyInfo")
    public Result getFamilyInfo(HttpServletRequest request){
        return familyService.getFamilyInfo(request);
    }


    /**
     * 修改家庭信息
     * @param family
     * @return
     */
    @PostMapping("/update")
    public Result updateFamilyInfo(@RequestBody Family family){
        return familyService.updateFamilyInfo(family);
    }

    /**
     * 获取家庭的所有用户信息
     * @param request
     * @return
     */
    @GetMapping("/member")
    public Result getFamilyMember(HttpServletRequest request){
        return familyMemberService.getFamilyMembers(request, new FamilyMember());
    }

    /**
     * 获得网站所有用户信息
     * @param familyMember
     * @return
     */
    @PostMapping("/allMember")
    public Result getAllMembers(@RequestBody FamilyMember familyMember){
        return familyMemberService.getAllFamilyMembers(familyMember);
    }

    @PostMapping("allFamily")
    public Result getAllFamily(@RequestBody Family family){
        return familyService.getAllFamily(family);
    }

    /**
     * 查询所有家庭成员的接口(带分页)
     * @param familyMember
     * @param request
     * @return
     */
    @PostMapping("/member")
    public Result getFamilyMember(@RequestBody FamilyMember familyMember, HttpServletRequest request){
        Result result = familyMemberService.getFamilyMembers(request, familyMember);
        return result;
    }

    /**
     * 增加一个家庭成员的接口
     * @param familyMember
     * @param request
     * @return
     */
    @PostMapping("/addMember")
    public Result addMember(@RequestBody FamilyMember familyMember, HttpServletRequest request){
        return familyMemberService.addMember(familyMember, request);
    }

    /**
     * 更新一个家庭成员信息的接口
     * @param familyMember
     * @return
     */
    @PostMapping("/updateMember")
    public Result updateMember(@RequestBody FamilyMember familyMember, HttpServletRequest request){
        return familyMemberService.updateMember(familyMember, request);
    }

    /**
     * 删除家庭成员的接口
     * @param ids
     * @return
     */
    @GetMapping("/deleteMember")
    public Result deleteMember(@RequestParam("ids") String ids){
        return familyMemberService.deleteMember(ids);
    }

    /**
     * 获得家庭通讯录的接口
     * @param request
     * @return
     */
    @GetMapping("/addressBook")
    public Result getAddressBook(HttpServletRequest request){
        return familyService.getAddressBook(request);
    }

    /**
     * 验证密码是否正确
     * @param password
     * @param request
     * @return
     */
    @GetMapping("/verifyPassword")
    public Result verifyPassword(@RequestParam("password") String password, HttpServletRequest request){
        return familyMemberService.verifyPassword(password, request);
    }

    /**
     * 修改用户密码
     * @param map
     * @param request
     * @return
     */
    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody Map map, HttpServletRequest request){
        return familyMemberService.updatePassword(map, request);
    }


}
